<template>
    <div id="dr32">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>商家管理</BreadcrumbItem>
            <BreadcrumbItem>无店铺信息</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">
            <Select v-model="type" style="width:200px;">
                <Option v-for="item in typeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select> &nbsp;
            <Input v-model="selectMobile" placeholder="查询手机号码" style="width: 150px"/>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>
            <Button type="info" @click="handleDownload()" style="float: right">下载报表</Button>
        </div>

        <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0" style="margin-top: 10px" @on-row-dblclick="rowData"></Table>

        <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
              style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
              v-if="data&&data.length>0"/>
        <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
            总计 {{pageTotal}} 条数据
        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>
        <Modal v-model="dealwith">
            <p slot="header" style="color:#444;text-align:center">
                <span>选择处理结果</span>
            </p>
            <div style="text-align:left;font-size: 16px;">
                <RadioGroup v-model="radioStr">
                    <Radio label="未拔打" style=" font-size: 18px;padding: 2px"></Radio>
                    <br>
                    <Radio label="拔打成功待用户处理" style=" font-size: 18px;padding: 2px"></Radio>
                    <br>
                    <Radio label="电话未接通" style=" font-size: 18px;padding: 2px"></Radio>
                    <br>
                </RadioGroup>
            </div>
            <div slot="footer">
                <Button type="info" @click="dealwith=false">取消</Button>
                <Button type="info" @click="dealWithData()">确认</Button>
            </div>
        </Modal>
    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                type: "2",
                typeList: [
                    {
                        value: '2',
                        label: '配件商'
                    },
                    {
                        value: '3',
                        label: '修理'
                    },
                    {
                        value: '4',
                        label: '补胎'
                    },
                    {
                        value: '5',
                        label: '审车'
                    },
                    {
                        value: '6',
                        label: '加油'
                    },
                    {
                        value: '7',
                        label: '吊车'
                    }
                ],
                selectMobile: "",
                radioStr: "未拔打",
                loading: false,
                dealwith: false,
                index: 0,
                pageTotal: 0,
                noStoreId: '',
                curPage: 0,
                columns: [
                    {
                        title: '注册时间',
                        key: 'registeTime1',
                        width: 150
                    },
                    {
                        title: '手机号码',
                        key: 'mobile',
                        width: 120
                    },
                    {
                        title: '角色类型',
                        key: 'type1',
                        width: 100
                    },
                    {
                        title: '店铺地址',
                        key: 'address'
                    },
                    {
                        title: '推荐码',
                        key: 'referrer',
                        width: 120
                    },
                    {
                        title: '审核状态',
                        key: 'isCheck1',
                        width: 100
                    },
                    {
                        title: '操作',
                        width: 150,
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    }, style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.dealwith = true;
                                            this.noStoreId = params.row._id;
                                            this.index = params.index;
                                        }
                                    }
                                }, '处理'), h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            var ds = this;
                                            this.$Modal.confirm({
                                                title: "提示",
                                                content: "确定删除用户?",
                                                onOk(){
                                                    ds.delData(params);
                                                },
                                                onCancel(){

                                                }
                                            });
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            typeChange(){
                this.getData();
            },
            pageChange(page){
                this.getData(page);
            },
            rowData(data, index){

            },
            search(){
                this.getData();
            },
            dealWithData(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('noStoreId', this.noStoreId);

                if (this.radioStr == '未拔打') {
                    param.append('isCheck', "0");
                }
                if (this.radioStr == '拔打成功待用户处理') {
                    param.append('isCheck', "1");
                }
                if (this.radioStr == '电话未接通') {
                    param.append('isCheck', "2");
                }
                this.loading = true;
                Axios.post(ipServer + "usercompany/updateStatusOfCheck", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                if (this.radioStr == '未拔打') {
                                    this.data[this.index].isCheck = 0;
                                    this.data[this.index].isCheck1 = '未拨打';
                                }
                                if (this.radioStr == '拔打成功待用户处理') {
                                    this.data[this.index].isCheck = 1;
                                    this.data[this.index].isCheck1 = '已处理';
                                }
                                if (this.radioStr == '电话未接通') {
                                    this.data[this.index].isCheck = 2;
                                    this.data[this.index].isCheck1 = '未接通';
                                }
                                this.$Message.info("处理成功!");
                                this.radioStr == '未拔打'
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                            this.dealwith = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            delData(data){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('noStoreId', data.row._id);
                this.loading = true;
                Axios.post(ipServer + "usercompany/deleteNoStore", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                this.data.splice(data.index, 1);
                                this.$Message.info("开启成功!");
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('userType', this.type);
                if (page) {
                    param.append('pageId', page + "");
                }
                if (this.selectMobile) {
                    param.append('shopMobile', this.selectMobile + "");
                }
                this.loading = true;
                Axios.post(ipServer + "usercompany/selectNoStore", param)
                        .then(res => {
                            if (res.data.code == 0) {

                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].registeTime1 = sessionUtils.timestampToTime(res.data.data.result[i].registeTime);
                                    if (res.data.data.result[i].workStatus == 1) {
                                        res.data.data.result[i].workStatus1 = "关闭";
                                    } else {
                                        res.data.data.result[i].workStatus1 = "开启";
                                    }

                                    if (res.data.data.result[i].isCheck == 0) {
                                        res.data.data.result[i].isCheck1 = "未拨打";
                                    } else if (res.data.data.result[i].isCheck == 1) {
                                        res.data.data.result[i].isCheck1 = "已处理";
                                    } else {
                                        res.data.data.result[i].isCheck1 = "未接通";
                                    }

                                    if (res.data.data.result[i].type == "1") {
                                        res.data.data.result[i].type1 = "司机";
                                    }
                                    if (res.data.data.result[i].type == "2") {
                                        res.data.data.result[i].type1 = "配件商";
                                    }
                                    if (res.data.data.result[i].type == "3") {
                                        res.data.data.result[i].type1 = "修理";
                                    }
                                    if (res.data.data.result[i].type == "4") {
                                        res.data.data.result[i].type1 = "补胎";
                                    }
                                    if (res.data.data.result[i].type == "5") {
                                        res.data.data.result[i].type1 = "审车";
                                    }
                                    if (res.data.data.result[i].type == "6") {
                                        res.data.data.result[i].type1 = "加油";
                                    }
                                    if (res.data.data.result[i].type == "7") {
                                        res.data.data.result[i].type1 = "吊车";
                                    }

                                }


                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }, handleDownload() {
                this.loading = true;
                const list = this.data;
                require.ensure([], () => {
                    const {export_json_to_excel} = require('../../assets/js/Export2Excel') //这个地址和页面的位置相关，这个地址是Export2Excel.js相对于页面的相对位置
                    const tHeader = ["注册时间", "手机号码", "角色类型", "店铺地址", "推荐码", "审核状态"]; //这个是表头名称 可以是iveiw表格中表头属性的title的数组
                    const filterVal = ["registeTime1", "mobile", "type1", "address", "referrer", "isCheck1"]; //与表格数据配合 可以是iview表格中的key的数组
                    const data = this.formatJson(filterVal, list)
                    export_json_to_excel(tHeader, data, '无店铺信息') //列表excel  这个是导出表单的名称
                    this.loading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>